<?php

/**
 * Created by PhpStorm.
 * User: dev
 * Date: 4/9/14
 * Time: 3:51 PM
 */
class Settings extends Eloquent
{

    public static $table = 'settings';
    public static $key = 'id';



    function __construct()
    {
        parent::__construct();
    }

    public static function get($lang = null, $variable = null)
    {
        if (!empty($variable)) {
            $value = DB::table('settings')
                ->where('variable', '=', trim($variable))
                ->where('lang', '=', trim($lang))
                ->only('value');
            return $value;
        } else {
            return "Invalid Settings...";
        }
    }

    public static function saveSetting($variable=null, $value=null)
    {
        if ($variable != null && $value != null) {
            $setting = Settings::where('variable', '=', $variable)->first();


            if (!$setting) {
                $s = array(
                    'variable' => $variable,
                    'value' => $value,
                    'updated_at' => Commoncall::current_timestamp(),
                    'created_at' => Commoncall::current_timestamp()
                );
                DB::table('settings')->insert($s);
            } else {
                DB::table('settings')
                    ->where('id', '=', $setting->id)
                    ->update(array(
                        'variable' => $variable,
                        'value' => $value,
                        'updated_at' => Commoncall::current_timestamp(),
                    ));
            }
        }
    }


}